| Fully Qualified Name: | CodeIgniter\Throttle\Throttler |
| Implements: | ThrottlerInterface |
Class Throttler
Uses an implementation of the Token Bucket algorithm to implement a "rolling window" type of throttling that can be used for rate limiting an API or any other request.
Each "token" in the "bucket" is equivalent to a single request for the purposes of this implementation.
| Name | Description | Defined By |
|---|---|---|
| __construct() | Constructor. | Throttler |
| check() | Restricts the number of requests made by a single IP address within a set number of seconds. | Throttler |
| getTokenTime() | Returns the number of seconds until the next available token will be released for usage. | Throttler |
| setTestTime() | Used during testing to set the current timestamp to use. | Throttler |
| time() | Return the test time, defaulting to current. | Throttler |
Constructor.
| Parameter Name | Type | Description |
|---|---|---|
| $cache | \type |
Returns:
Restricts the number of requests made by a single IP address within a set number of seconds.
Example:
if (! $throttler->check($request->ipAddress(), 60, MINUTE)) {
die('You submitted over 60 requests within a minute.');
}
| Parameter Name | Type | Description |
|---|---|---|
| $key | string | The |
| $capacity | int | The |
| $seconds | int | The |
| $cost | int | The |
Returns: bool
Returns the number of seconds until the next available token will be released for usage.
Returns: int
Used during testing to set the current timestamp to use.
| Parameter Name | Type | Description |
|---|---|---|
| $time | int |
Returns: $this
Return the test time, defaulting to current.
Returns: int